package com.mywang.weitravel.modules.mine;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.mywang.weitravel.R;
import com.mywang.weitravel.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class ResetPwdActivity extends BaseActivity<ResetPwdPresenter> implements ResetPwdContract.View {

    public static void launch(Activity activity) {
        Intent intent = new Intent(activity, ResetPwdActivity.class);
        launchActivity(activity, intent);
    }

    @BindView(R.id.iv_title_back)
    ImageView ivTitleBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.et_orginal_pwd)
    EditText etOriginalPwd;
    @BindView(R.id.et_new_pwd)
    EditText etNewPwd;
    @BindView(R.id.et_confirm_pwd)
    EditText etConfirmPwd;
    @BindView(R.id.bt_change)
    Button btChange;

    @Override
    protected void initView() {
        tvTitle.setText("密码设置");
    }

    @OnClick({R.id.iv_title_back, R.id.bt_change})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_title_back:
                finish();
                break;
            case R.id.bt_change:
                if (check()) {
                    mPresenter.changePwd(etOriginalPwd.getText().toString(), etConfirmPwd.getText().toString());
                }
                break;
        }
    }

    private boolean check() {
        if (TextUtils.isEmpty(etOriginalPwd.getText().toString().trim())) {
            ToastUtils.showShort("请输入原密码");
            return false;
        }
        if (TextUtils.isEmpty(etNewPwd.getText().toString().trim())) {
            ToastUtils.showShort("请输入新密码");
            return false;
        }
        if (TextUtils.isEmpty(etConfirmPwd.getText().toString().trim())) {
            ToastUtils.showShort("请确认密码");
            return false;
        }
        if (!etConfirmPwd.getText().toString().equals(etNewPwd.getText().toString())) {
            ToastUtils.showShort("密码不一致");
            return false;
        }
        return true;
    }

    @Override
    protected ResetPwdPresenter initPresenter() {
        return new ResetPwdPresenter(this);
    }


    @Override
    protected int getActivityLayoutID() {
        return R.layout.activity_reset_pwd;
    }

    @Override
    public void changePwdSuccessful() {
        ToastUtils.showShort("密码修改成功");
        finish();
    }
}
